<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2016/9/28
 * Time: 9:11
 */

$list = [];
//创建临时存储内存
for ($i = 0;$i<20;$i++){
    $list[] = [
        'id' => $i,
        'c1' => 'c1--'.$i,
        'c2' => 'c2--'.$i,
        'c3' => 'c3--'.$i,
        'c4' => time(),
    ];
}
//$list = [
//    [
//        'id' => $i++,
//        'c1' => 'c1--'.$i,
//        'c2' => 'c2--'.$i,
//        'c3' => 'c3--'.$i,
//        'c4' => time(),
//    ],
//];
$fp = fopen('php://memory','w');
fputcsv($fp,array('id','列1','列2','列3','列4'),';');
foreach($list as $item) {
    fputcsv($fp,array($item['id'],$item['c1'],$item['c2'],$item['c3'],date('Y-m-d H:i:s',$item['c4'])),';');
}

rewind($fp);
$content = "";
while(!feof($fp)){
    $content .= fread($fp,1024);
}
fclose($fp);
//$content = iconv('utf-8','utf-8',$content);//转成gbk，否则excel打开乱码
echo $content;
exit;